package com.jumper.property.comparer.formatter;

import com.jumper.property.comparer.core.constant.FormatConstant;
import com.jumper.property.comparer.diff.DiffVal;

import java.util.List;
import java.util.stream.Collectors;

public class ObjectDiffFormatter extends AbstractDiffFormatter {

    private final String propertyName;
    private final List<DiffVal> subDiffs;

    public ObjectDiffFormatter(String propertyName, List<DiffVal> subDiffs) {
        this.propertyName = propertyName;
        this.subDiffs = subDiffs;
    }

    @Override
    public String format() {
        List<String> diffValues = subDiffs.stream().map(DiffVal::getDiffValue).collect(Collectors.toList());
        return pattern.getObjectDiffPattern()
                .replace(FormatConstant.DISPLAY_PROPERTY_KEY, propertyName)
                .replace(FormatConstant.ROW_CHANGE_DATA_KEY, String.join(pattern.getInlineJoinDiffPattern(), diffValues));
    }
}
